package cn.tedu.recruitmentwebsite.admin.controller;

import cn.tedu.recruitmentwebsite.admin.pojo.dto.UserQuery;
import cn.tedu.recruitmentwebsite.admin.pojo.dto.UserSaveParam;
import cn.tedu.recruitmentwebsite.admin.pojo.vo.UserVO;
import cn.tedu.recruitmentwebsite.admin.service.AdminService;
import cn.tedu.recruitmentwebsite.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;

@RestController
@RequestMapping("/admin/")
@Slf4j
public class AdminController {
    @Autowired
    private AdminService adminService;
    @GetMapping("query")
    public JsonResult query(UserQuery userQuery){
        log.info("查询用户控制层，参数：{}",userQuery);
        List<UserVO> userVO = adminService.query(userQuery);
        for (UserVO user:userVO){
            log.info("查询用户控制层，查询结果：{}",user);
        }
        return JsonResult.ok(userVO);
    }

    @PostMapping("save")
    public JsonResult save(UserSaveParam userSaveParam){
        log.debug("保存用户控制层，参数：{}",userSaveParam);
        adminService.save(userSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("update/status/{id}/{userStatus}")
    public JsonResult update(@PathVariable  Long id, @PathVariable String userStatus){
        log.debug("更新用户控制层，参数：{},{}",id,userStatus);
        adminService.update(id,userStatus);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id){
        log.debug("删除用户控制层，参数：{}",id);
        adminService.delete(id);
        return JsonResult.ok();
    }
}
